package com.ruimei;

import java.io.File;

import javax.servlet.MultipartConfigElement;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.Data;

@Data
@Configuration
public class UploadFileConfig {
	
 public static String save;
 @Value("${file.uploader.uploadFolder}")
 private  String uploadFolder;

    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        File path = new File(uploadFolder);
        if(path.exists()) {
        	path.mkdir();
        }
        factory.setLocation(uploadFolder);  
        if(StringUtils.isNotBlank(uploadFolder)) {
        	this.save = uploadFolder ;
        }
        return factory.createMultipartConfig();
    }

	
    
}
